package com.hpsk.swagger.shejimoshi.test1;

import com.hpsk.common.RespResult;
import com.hpsk.common.RespUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangwang2832511019
 */
@RestController
@Slf4j
@Tag(name = "工厂模式")
@RequestMapping("/factory")
public class FactoryController {

    @Operation(summary = "工厂模式测试")
    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public RespResult<String> test() {
//        int a =1;
        Factory01Enums factory01Enums = Factory01Enums.FACTORY_01_ENUMS;
        ClassLoader defaultClassLoader = ClassUtils.getDefaultClassLoader();
        log.info("defaultClassLoader:{}", defaultClassLoader);
        //boolean isPresent(String className, @Nullable ClassLoader classLoader)判断当前classLoader是否包含目标类型（包括它的所有父类和接口）：
        if (ClassUtils.isPresent("com.hpsk.swagger.shejimoshi.test1.Factory01Enums", ClassUtils.getDefaultClassLoader())) {
            log.info("存在");
        } else {
            log.info("不存在");
        }
        log.info("加载类Factory01Enums:{}",ClassUtils.resolvePrimitiveClassName("com.hpsk.swagger.shejimoshi.test1.Factory01Enums"));
        //ClassLoader overrideThreadContextClassLoader(@Nullable ClassLoader classLoaderToUse)用特定的类加载器覆盖当前线程上下文的类加载
        ClassUtils.overrideThreadContextClassLoader(ClassLoader.getSystemClassLoader().getParent());
        log.info("修改后的加载类:{}",ClassUtils.getDefaultClassLoader());
        return RespUtils.ok();
    }
}
